package com.zdd.ehe.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zdd.ehe.entity.Permission;
import com.zdd.ehe.entity.Role;
import com.zdd.ehe.entity.User;
import com.zdd.ehe.mapper.UserMapper;
import com.zdd.ehe.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ZhuiZhu
 * @since 2023-03-13
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
    @Resource
    private UserMapper userMapper;

    /**
     * 获取用户角色列表
     *
     * @param id
     * @return
     */
    @Override
    public List<String> getRoles(Integer id) {
        List<String> roleList = userMapper.getRoles(id);
        return roleList;
    }

    /**
     * 插入用户数据
     *
     * @param user
     * @return
     */
    @Override
    public int insert(User user) {
        int result = userMapper.insert(user);
        return result;
    }

    /**
     * 分页查询用户列表
     *
     * @param page
     * @return
     */
    @Override
    public Page<User> getalluserbypage(Page<User> page) {
        Page<User> pagex = userMapper.getalluserbypage(page);
        return pagex;
    }

    /**
     * 修改用户数据
     *
     * @param user
     * @return
     */
    @Override
    public int updateUser(User user) {
        int result = -1;
        try{
            result = userMapper.updateById(user);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }





}
